Feb 13, 2019

Why interactive visualization

  • Static display
    • good for publication
    • effective to show very specific pattern
  • Interactive display
    • gives end user more flexibility
    • exploratory visualization is convenient

R packages for this lecture

install.packages(c("ggplot2","plotly", "DT", "gapminder"))
  • gapminder data is used from gapminder package
library(gapminder)
dat <- subset(gapminder, year==2007)

Life expectancy data

library(ggplot2)
p <- ggplot(dat, aes(x = log(gdpPercap), y = lifeExp))+
  geom_point(aes(size = sqrt(pop/pi)), pch = 21, show.legend = FALSE) +
   scale_size_continuous(range=c(1,30)) + aes(fill = continent)
p

Interactive visualization

library(plotly)
ggplotly(p + aes(label = country))

Animation using plotly

q <- ggplot(gapminder, aes(x = log(gdpPercap), y = lifeExp, frame=year))+
  geom_point(aes(size = sqrt(pop/pi)), pch = 21, show.legend = FALSE) +
   scale_size_continuous(range=c(1,30)) + aes(fill = continent)
ggplotly(q + aes(label = country))

Interactive display of tables

library(DT)
datatable(dat)

3D scatterplot

plot_ly(gapminder, x = ~gdpPercap, y = ~lifeExp, z = ~continent) %>%
  add_markers(color = ~continent)

References